var pathName=window.document.location.pathname;  
var g_path=pathName.substring(0,pathName.substr(1).indexOf('/')+1); 
function printTicket(arr,callback){
	if (typeof(SWI)!='undefined'&&eval(SWI.util.getParameter('system', 'newSeatMap'))) {
		SWI.util.printTicket(arr, callback);
		return;
	}
	if(typeof(callback)!='undefined'){
		callback();
	}
	//return;
	var LODOP=getLodop();
	var iPrinterCount=LODOP.GET_PRINTER_COUNT();
	var printerName = "EPSON LQ-630K ESC/P 2 Ver 2.0";
	for(var i=0;i<iPrinterCount;i++){
		var name = LODOP.GET_PRINTER_NAME(i);
		if(name.indexOf("Epson LQ-1600K")!==-1||name.indexOf("Print2Flash 3 Printer")!==-1){
			printerName = name;
			break;
		}
	};	
	var left =490;
	var height = 30;
	var h,h3;
	jQuery(arr).each(function(i,infos){
	     //LODOP.PRINT_INITA(0,10,504,196,"");
	     //LODOP.SET_PRINT_PAGESIZE(1,504,196,"A4");
		 LODOP.SET_PRINTER_INDEX(printerName);
		 h =0;
		 h3 = 16;
		 LODOP.SET_PRINT_STYLE("FontSize",14);
		 
		 //LODOP.ADD_PRINT_TEXT(39,200,180,height,infos['saleNo']);
		 //LODOP.ADD_PRINT_TEXT(h3 = h3 + 15,10,180,height,infos['saleNo']);
		 //LODOP.ADD_PRINT_TEXT(h3 = h3 + 15,10,180,height,infos['price']+"元");
		 //LODOP.ADD_PRINT_TEXT(h = h+15,left,180,height,"流水号:"+infos['sn']);
         //LODOP.SET_PRINT_STYLE("FontSize",9);
         //LODOP.SET_PRINT_STYLE("FontSize",7);
         //if(infos.priceShowType!=3)
         LODOP.ADD_PRINT_TEXT(10,10,180,height,infos['createTime'].substring(0,10));
         LODOP.ADD_PRINT_TEXT(122,230,180,height,infos['playDate'].substring(0,10));
         LODOP.ADD_PRINT_TEXT(65,60,180,height,infos['price']);
         LODOP.ADD_PRINT_TEXT(90,10,180,height,infos['saleNo']+"-"+infos['ticket_num']);

         //LODOP.ADD_PRINT_TEXT(h = h+15,left,180,height,infos["belongto"]==1?"田汉大剧院":"红太阳演义中心");
		 LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"价格:"+infos['price']+"元");
		 if(infos['seatName']){
			 LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"座位:"+infos['seatName']);
		 }
		 LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,""+infos['number']);
		 if(infos['descs']){
         	 LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"备注:"+infos['descs']);
         }
         if(infos['gift']){
             LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,infos['gift']);
         }
         //湖南看台
         if(infos['seat_id']=="3581"){
             LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"限12人");
         }
         //长沙看台
         if(infos['seat_id']=="4095"){
             LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"限14人");
         }
         //VS、VT
         if(infos['seat_id']=="3622"||infos['seat_id']=="3657"){
             LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"限18人");
         }
         //VS1、VS2、VT1、VT2
         if(infos['seat_id']=="3640"||infos['seat_id']=="3631"||infos['seat_id']=="3675"||infos['seat_id']=="3666"){
             LODOP.ADD_PRINT_TEXT(h = h+30,left,360,height,"限9人");
         }
		 //LODOP.ADD_PRINT_BARCODE(h = h+12,left+20,90,90,"QRCode",infos['number']);
		 
		 LODOP.PRINT(); 
	});
	if(typeof(callback)!='undefined'){
		callback();
	}
	
}

function ajustHeight(){
    var eh = 0;
    var elements = $("body").children(":not(script):not(link)");
    elements.each(function(i,div){
		eh += $(div).height();
	});
	//$(top.document).find("iframe[name=mainFrame]").height(eh);
	/*var h = $(top).height()-80;
	var elements = $("body").children(":not(script):not(link)");
	var eh = 0;
	var element = null;
	elements.each(function(i,div){
		eh += $(div).height();
		element = div;
	})
	if(eh>h){
		$(top.document).find("iframe[name=mainFrame]").height(eh);
		$(top.document).find("div.mainl").height(eh);
	}else{
		$(top.document).find("iframe[name=mainFrame]").height(h);
		$(top.document).find("div.mainl").height(h);
		if($(element).find("div.rcon2").length>0){
			$(element).find("div.rcon2").height((h-eh)+$(element).height());
		}else if($(element).find("div.rcon").legnth>0){
			$(element).find("div.rcon").height((h-eh)+$(element).height());
		}else{
			$(element).height((h-eh)+$(element).height());
		}
		
	}*/
}
function ajustHeight2(){
	var h = $(top).height()-80;
	var elements = $("body").children(":not(script)");
	var eh = 0;
	var element = null;
	elements.each(function(i,div){
		eh += $(div).height();
		element = div;
	})
	if(eh>h){
	alert(eh);
		$(top.document).find("iframe[name=mainFrame]").height(eh);
		$(top.document).find("div.mainl").height(eh);
	}else{
		$(top.document).find("iframe[name=mainFrame]").height(h);
		$(top.document).find("div.mainl").height(h);
		$(element).height((h-eh)+$(element).height());
	}
}
function getDicValue(dic,value){
	var v = "";
	if(dic.indexOf(" from ")==-1){
		var dicObj = window['dic'+dic];
		if(dicObj){
			v = dicObj[value]["text"];
		}
	}else{
		dwr.engine.setAsync(false);
		DbServices.queryEntityDicValue(dic,value,function(ret){
			if(ret!=null)
				v = ret[1];
		});
	}
	return v;
}
function genDicJs(arr){
	$.ajax({
		url:g_path + '/public/tool/gendicjs.htmls',
		data:{'data':arr},
		dataType:'json',
		type:'POST',
		async:false,
		success:function(ret){
			document.write("<script>");
			for(var i=0;i<ret.length;i++){
				var obj = ret[i];
				document.write("var dic"+obj.code +"=" +JSON.stringify(obj.dicMap)+";");
			}
			
			document.write("</script>");
		}
	})
}
function genMaps(hql){
	var obj = null;
	$.ajax({
		url:g_path + '/public/tool/genMaps.htmls',
		data:{hql:hql},
		dataType:'json',
		type:'POST',
		async:false,
		success:function(ret){
			obj = ret;
		}
	})
	return obj;
}

/**
 * 生成下拉菜单
 * 
 * @param strategys 数据
 * @param id 可指定下拉菜单的id，如果找不到则把id赋值给下拉菜单
 * @returns 下拉菜单html代码
 */
function joinSelect(strategys,id){
	if(arguments.length>1){
		var str = _.map(strategys,function(obj,key){
			return "<option value='"+obj.id+"'>" + obj.name + "</option>";
		})
		var se = null;
		se = $('select[id="' + id + '"]');
		if (!se || se.length == 0) {
			se = $('<select id="' + id + '">');
		}
		return se.append("<option value=''>==请选择==</option>"+str);
	}else{
		var conf = arguments[0];
		var str = _.map(conf.data,function(obj,key){
			return "<option value='"+obj[conf.valueKey]+"'>" + obj[conf.textKey] + "</option>";
		})
		return $('<select>').append("<option value=''>==请选择==</option>"+str);
	}
	
}

function joinSelect4Dic(strategys,id){
	var str = _.map(strategys,function(obj,key){
		return "<option value='"+obj.code+"'>" + obj.text + "</option>";
	})
	var se = null;
	se = $('select[id="' + id + '"]');
	if (!se || se.length == 0) {
		se = $('<select id="' + id + '">');
	}
	return se.append("<option value=''>==请选择==</option>"+str);
}

/**
 * 生成数据字典的下拉菜单
 * 
 * @param dic 数据字典的类别，4位长度
 * @param id 可指定下拉菜单的id，如果找不到则把id赋值给下拉菜单
 * @returns 下拉菜单html代码
 */
function dicSelect(dic, id){
	var arr = _.map(dic,function(obj,key){
		return "<option value='"+obj.code+"'>" + obj.text + "</option>";
	})
	var se = null;
	if (id != null) {
		se = $('select[id="' + id + '"]');
	}
	if (!se || se.length == 0) {
		se = $('<select' + (id ? ' id="' + id + '" ' : '') + '>');
	}
	// IE不能用prepend方法
	se.append("<option value=''>==请选择==</option>" + arr.join(""));
	return se;
}
function popSelectWin(obj,title,url,callback,width,height){
	//var url = g_path+"/public/common/r2.htmls?page=abc/user/userWin";
	if(!width){
		width = 660;
	}
	if(!height){
		height = 450;
	}
	layer.open({
		title:title,
		skin: 'layui-layer-lan',
	    type: 2,
	    area: [width+'px', height+'px'], //宽高
	    content:url,
	    btn:["确定","取消"],
	    yes:function(index,layero){
	    	callback(index,layero);
	    }
	});
}
function onlyDigit(e){  
    var charCode = e.charCode ? e.charCode : e.keyCode;  
    if(charCode<48 || charCode >57){  
        return false;  
    }else{  
        return true;      
    }  
} 
function isNumber(num)
{
     var re = /^[\d.]+$/;      
     if (!re.test(num))
    {
        return false;
     }
     return true;
}
function getCurrentTime(pattern){
	pattern = (pattern===undefined?"yyyy-MM-dd":pattern);
	var value = "";
	$.ajax({
		url:g_path + '/public/tool/genCurrentTime.htmls',
		data:{'pattern':pattern},
		dataType:'html',
		type:'POST',
		async:false,
		success:function(ret){
			value = ret;
		}
	})
	return value;
}
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}
function getDateOfPreMonth(dt) {
    /// <summary>
    /// 返回上一月的日期
    ///create by 长江 20121225
    /// </summary>
    /// <returns type="Date" />
    /// <param name="dt" type="Date">
    ///     参照日期，若为空则为当前时间
    /// </param>
    if (typeof dt == 'undefined') { dt = (new Date()); }
    var y = (dt.getMonth() == 0) ? (dt.getFullYear() - 1) : dt.getFullYear();
    var m = (dt.getMonth() == 0) ? 11 : dt.getMonth() - 1;
    var preM = getDayOfMonth(y, m);
    var d = (preM < dt.getDate()) ? preM : dt.getDate();
    return new Date(y, m, d);
}
function getDayOfMonth(y, Mm) {
    /// <summary>
    /// 计算当前月一共多少天
    ///create by 长江 20121225
    /// </summary>
    /// <returns type="Number" />
    /// <param name="y" type="Number">
    ///     年,若为空则为当前时间
    /// </param>
    /// <param name="Mm" type="Number">
    ///     月,0开始,若为空则为当前时间
    /// </param>
    if (typeof y == 'undefined') { y = (new Date()).getFullYear(); }
    if (typeof Mm == 'undefined') { Mm = (new Date()).getMonth(); }
    var Feb = (y % 4 == 0) ? 29 : 28;
    var aM = new Array(31, Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    return  aM[Mm];
};

function generateMixed(n) {
var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];

     var res = "";
     for(var i = 0; i < n ; i ++) {
         var id = Math.ceil(Math.random()*35);
         res += chars[id];
     }
     return res;
}

function trim(s) {
    if (s.length > 0) {
        if (s.charAt(0) == " " || s.charAt(0) == "," || s.charAt(0) == "|")
            s = s.substring(1, s.length);
        if (s.charAt(s.length - 1) == " " || s.charAt(s.length - 1) == "," || s.charAt(s.length - 1) == "|")
            s = s.substring(0, s.length - 1);
        if (s.charAt(0) == " " || s.charAt(0) == "," || s.charAt(0) == "|" || s.charAt(s.length - 1) == " " || s.charAt(s.length - 1) == "," || s.charAt(s.length - 1) == "|")
            return trim(s);
    }
    return s;
}

function checkAlls(id, obj) {
    var el = $('#' + id + ' input');
    var len = el.length;
    for (var i = 0; i < len; i++) {
        if (el[i].type == "checkbox") {
            el[i].checked = true;
        }
    }
    $(obj).attr("onclick", "clearAlls('" + id + "',this)");
}

function clearAlls(id, obj) {
    var el = $('#' + id + ' input');
    var len = el.length;
    for (var i = 0; i < len; i++) {
        if (el[i].type == "checkbox") {
            el[i].checked = false;
        }
    }
    $(obj).attr("onclick", "checkAlls('" + id + "',this)");
}

function clearHtml(html){
    var dd=html.replace(/<\/?.+?>/g,"");
    var dds=dd.replace(/ /g,"");//dds为得到后的内容
    return dds;
}